package frist50;

import java.util.Arrays;

public class T0031 {
    public void nextPermutation(int[] nums) {
        int maxId=nums.length-1;
        for (int i = nums.length-1; i >0 ; i--) {
            if (nums[i]<=nums[i-1]){
                maxId=i-1;
            }else{
                break;
            }
        }
        if (maxId==0) {
            Arrays.sort(nums);
            return;
        }
        for (int i = nums.length-1; i >=maxId ; i--) {
            if (nums[i]>nums[maxId-1]){
                int tmp=nums[i];
                nums[i]=nums[maxId-1];
                nums[maxId-1]=tmp;
                break;
            }
        }
        Arrays.sort(nums,maxId,nums.length);
        return;
    }

}
